/**
 * 应用配置
 * 从环境变量中读取配置信息
 */
export default () => ({
  // 应用配置
  app: {
    environment: process.env.NODE_ENV || 'development',
    port: parseInt(process.env.PORT || '3000', 10),
    name: 'Life Record API',
  },

  // 数据库配置
  database: {
    host: process.env.DB_HOST,
    port: parseInt(process.env.DB_PORT || '3306', 10),
    username: process.env.DB_USERNAME,
    password: process.env.DB_PASSWORD,
    name: process.env.DB_NAME,
  },

  // Redis 配置
  redis: {
    host: process.env.REDIS_HOST,
    port: parseInt(process.env.REDIS_PORT || '6379', 10),
    password: process.env.REDIS_PASSWORD,
  },

  // JWT 配置
  jwt: {
    secret: process.env.JWT_SECRET,
    expiresIn: process.env.JWT_EXPIRES_IN || '1h', // Access Token 默认 1 小时
    refreshExpiresIn: process.env.JWT_REFRESH_EXPIRES_IN || '7d', // Refresh Token 默认 7 天
    issuer: process.env.JWT_ISSUER,
    audience: process.env.JWT_AUDIENCE,
    algorithm: process.env.JWT_ALGORITHM,
    strictDeviceCheck: process.env.JWT_STRICT_DEVICE_CHECK === 'true', // 是否严格检查设备指纹
    riskThreshold: parseInt(process.env.JWT_RISK_THRESHOLD || '60', 10), // 风险评分阈值
  },

  // AWS 配置
  aws: {
    accessKeyId: process.env.AWS_ACCESS_KEY_ID,
    secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
    region: process.env.AWS_REGION,
  },
  // 微信小程序配置
  wechat: {
    appId: process.env.WECHAT_APP_ID,
    appSecret: process.env.WECHAT_APP_SECRET,
  },

  // 功能开关
  features: {
    enableEmailVerification: process.env.ENABLE_EMAIL_VERIFICATION === 'true',
    maxFileSize: parseInt(
      process.env.MAX_FILE_SIZE || `${5 * 1024 * 1024}`,
      10,
    ), // 5MB
  },
});
